package com.muyu.requset;

import com.muyu.entity.UserEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @ClassName: SaveUserRequest
 * @Author: Zirun.Xin
 * @Date: 2025/3/21 下午2:41
 * @Version: 1.0
 * @Description: 添加用户请求对象
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@ApiModel(value = "添加用户请求体", description = "添加用户所需参数")
public class SaveUserRequest {

    /**
     * 用户名
     */
    @ApiModelProperty(value = "用户名", example = "张三", required = true)
    private String name;

    /**
     * 年龄
     */
    @ApiModelProperty(value = "年龄", example = "0", required = true)
    private Integer age;

    /**
     * 性别
     */
    @ApiModelProperty(value = "性别", example = "男", required = true)
    private String sex;

    /**
     * 住址
     */
    @ApiModelProperty(value = "住址", example = "江苏南京", required = true)
    private String address;

    /**
     * 描述
     */
    @ApiModelProperty(value = "描述", example = "这是db1的用户", required = true)
    private String describes;

    /**
     * 头像
     */
    @ApiModelProperty(value = "头像", example = "./template/image/张三.jpg", required = true)
    private String image;

    /**
     * 将 {@link SaveUserRequest} 对象转换为 {@link UserEntity} 对象。
     * 该方法通过提取请求中的用户信息，构建并返回一个用户实体对象。
     *
     * @param request 包含用户信息的请求对象，不能为 {@code null}。
     * @return 转换后的 {@link UserEntity} 对象，包含从请求中提取的用户信息。
     */
    public static UserEntity convertToUserEntity(SaveUserRequest request) {
        return UserEntity.builder()
                .name(request.getName())
                .age(request.getAge())
                .sex(request.getSex())
                .address(request.getAddress())
                .describes(request.getDescribes())
                .image(request.getImage())
                .build();
    }
}
